<template>
  <div class="clock-container" style="margin: 0 auto">
    <flip-item :total="2" :current="timeArr[0]" />
    <flip-item :total="9" :current="timeArr[1]" />
    <div class="colon"></div>
    <flip-item :total="5" :current="timeArr[2]" />
    <flip-item :total="9" :current="timeArr[3]" />
    <div class="colon"></div>
    <flip-item :total="5" :current="timeArr[4]" />
    <flip-item :total="9" :current="timeArr[5]" />
  </div>
</template>

<script>
import FlipItem from './FlipItem.vue';
import { getTimeArr } from '../utils.js';

export default {
  components: {
    FlipItem,
  },
  data() {
    return {
      timeArr: getTimeArr(),
    };
  },
  mounted() {
    this.startTimer();
  },
  beforeUnmount() {
    this.stopTimer();
  },
  methods: {
    startTimer() {
      this.stopTimer();
      this.timer = setTimeout(() => {
        this.timeArr = getTimeArr();

        this.startTimer();
      }, 1000);
    },
    stopTimer() {
      clearTimeout(this.timer);
    },
  },
};
</script>

<style lang="scss" scoped>
.clock-container {
  display: flex;
  align-items: center;
  justify-content: center;
}

.colon {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: 50px;
  padding: 0 0.5vw;
  color: #fff;

  &::after,
  &::before {
    display: block;
    width: 10px;
    height: 10px;
    content: '';
    background: rgb(0 0 0 / 70%);
    border-radius: 50%;
  }
}
</style>
